import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_web_study/utils/sp_utils.dart';
import 'package:flutter_web_study/view_model/main_view_model.dart';
import 'package:provider/provider.dart';

import 'router/application.dart';
import 'router/routes.dart';

void main() {
  final router = FluroRouter();
  Routes.configureRoutes(router);
  Application.router = router;
  runApp(MyApp());
}

class MyApp extends StatelessWidget {

  MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [ChangeNotifierProvider.value(value: MainViewModel())],
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: '审核测试版'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var userId = "";

  @override
  Widget build(BuildContext context) {
    SpUtils.getInstance().then((value) {
      userId = SpUtils.get("userId").toString().trim() ?? "";
      print("$userId");
      Navigator.pop(context);
      Application().navigatePushToPage(context, userId == "null"? Routes.loginPage:Routes.homePage, {});
    });
    return Scaffold(
      appBar: AppBar(title: Text("甜甜圈后台管理系统")),
    );
  }
}
